package su.mvc.action.image;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.logging.Logger;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import su.mvc.action.ActionSupport;
import su.mvc.model.Picutre;


@Results(value = {
        @Result(name = ActionSupport.IMAGE, type = ActionSupport.IMAGE)
})
@ParentPackage("imagePack")
public class PictureAction  extends ActionSupport {

    private static final Logger log = Logger.getLogger(PictureAction.class.getName());



    private byte[] imageInByte = null;
    private Long imageId;
    private Picutre picutre;
    private String contentType;
    
    public String execute() throws Exception{
        picutre = getObjectify().get(Picutre.class, getImageId());
        setImageInByte(picutre.getPicture());
        setContentType(picutre.getContentType());
        return IMAGE;
    }


    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public byte[] getImageInByte() {
        return imageInByte;
    }

    public void setImageInByte(byte[] imageInByte) {
        this.imageInByte = imageInByte;
    }

    public Long getImageId() {
        return imageId;
    }

    public void setImageId(Long imageId) {
        this.imageId = imageId;
    }


}
